package com.bw.controller;

import com.bw.entity.TbProject;
import com.bw.entity.TbUser;
import com.bw.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class ProjectController {

    @Autowired
    private ProjectService projectService;

//      @RequestMapping("tologin")
//      public String tologin(){
//          return "login";
//      }
//
//      @PostMapping("login")
//      public String index(@RequestBody TbUser tbuser){
//          TbUser tbUser = projectService.login(tbuser);
//          if(tbUser!=null){
//              System.out.println("1111111111111111111111111111111");
//              return "ok";
//          }
//          return "no";
//      }

    //项目管理列表
    @GetMapping("getprojectList")
    public List getprojectList(@RequestParam(defaultValue = "")String mohu){
        return projectService.getprojectList(mohu);
    }
    //启用按钮
    @GetMapping("qi")
    public void qi(@RequestParam("ids")String ids){
        String[] split = ids.split(",");
        for(String id : split){
            this.projectService.qi(id);
        }
    }

    //停用按钮
    @GetMapping("ting")
    public void ting(@RequestParam("ids")String ids){
        String[] split = ids.split(",");
        for(String id : split){
            this.projectService.ting(id);
        }
    }

    //批删操作
    @GetMapping("delete")
    public void delete(@RequestParam("ids")String ids){
        String[] split = ids.split(",");
        for(String id : split){
            this.projectService.delete(id);
        }
    }

    //查询用户列表
    @GetMapping("getuserlist")
    public List getuserlist(){
        return projectService.getuserlist();
    }

    //查询接口列表
    @GetMapping("getinsertlist")
    public List getinsertlist(@RequestParam(defaultValue = "")String mohu){
        return projectService.getinsertlist(mohu);
    }
    //添加项目管理
    @PostMapping("add")
    public void add(@RequestBody TbProject project){
        System.out.println(project);
        this.projectService.add(project);
    }
    //用户分配
    @GetMapping("userfp")
    public void userfp(@RequestParam("ids")String ids,@RequestParam("id")int id){
         this.projectService.userfp(ids,id);
    }
    //接口分配
    @GetMapping("interfp")
    public void interfp(@RequestParam("ids")String ids,@RequestParam("id")int id){
        this.projectService.interfp(ids,id);
    }
    //接口调用列表
    @GetMapping("calllist")
    public List calllist(@RequestParam(defaultValue = "") String tid){
        return this.projectService.calllist(tid);
    }


}
